/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.26                          *
*        Compiled Aug  8 2014, 14:49:54                              *
*        (c) 2013 Segger Microcontroller GmbH & Co. KG               *
*                                                                    *
**********************************************************************
*                                                                    *
*        Internet: www.segger.com  Support: support@segger.com       *
*                                                                    *
**********************************************************************
*/

// USER START (Optionally insert additional includes)
// USER END

#include<stdlib.h>
#include "DIALOG.h"
#include "DLG.h"
#include "stdio.h"
#include "rtc.h"

extern WM_HWIN confing_dialog;
/*********************************************************************
*
*       Defines
*
**********************************************************************
*/
#define ID_WINDOW_0        (GUI_ID_USER + 0x00)
#define ID_BUTTON_0        (GUI_ID_USER + 0x07)
#define ID_BUTTON_1        (GUI_ID_USER + 0x06)	
#define ID_LISTWHEEL_0 (GUI_ID_USER + 0x01)
#define ID_LISTWHEEL_1 (GUI_ID_USER + 0x02)
#define ID_LISTWHEEL_2 (GUI_ID_USER + 0x03)
#define ID_LISTWHEEL_3 (GUI_ID_USER + 0x04)
#define ID_LISTWHEEL_4 (GUI_ID_USER + 0x05)
#define ID_TEXT_0        (GUI_ID_USER + 0x8)
#define ID_TEXT_1        (GUI_ID_USER + 0x9)

extern GUI_FONT GUI_Fonttime;
extern GUI_FONT GUI_Fontshuju_anniu40;

char Year[10];
char Month[10];
char Day[10];
char Hour[10];
char Min[10];


/*********************************************************************
*
*       Static data
*
**********************************************************************
*/


/*********************************************************************
*
*       _aDialogCreate
*/

static char *_apYear[] = {
  "2000", "2001", "2002", "2003",
  "2004", "2005", "2006", "2007", 
	"2008", "2009", "2010","2011", 
	"2012", "2013", "2014", "2015",
	"2016", "2017","2018", "2019", 
	"2020","2021","2022","2023",
	"2024","2025","2026","2027",
	"2028","2029","2030","2031"
};

static char *_apMonth[] = {
  "1",
  "2",
  "3",
  "4",
  "5",
  "6",
  "7",
  "8",
  "9",
  "10",
  "11",
  "12",
};

static char *_apDay[] = {
  "01", "02", "03", "04",
  "05", "06", "07", "08",
  "09", "10", "11", "12",
  "13", "14", "15", "16",
  "17", "18", "19", "20",
  "21", "22", "23", "24",
  "25", "26", "27", "28",
  "29", "30", "31",
};

static char* _apHour[] = {
	"1","2","3","4","5","6"
	"7","8","9","10","11","12",
	"13","14","15","16","17","18",
	"19","20","21","22","23","24",
};
static char* _apMin[] = {
  "01", "02", "03", "04",
  "05", "06", "07", "08",
  "09", "10", "11", "12",
  "13", "14", "15", "16",
  "17", "18", "19", "20",
  "21", "22", "23", "24",
  "25", "26", "27", "28",
  "29", "30", "31", "32",
	"33", "34", "35", "36",
	"37", "38", "39", "40",
	"41", "42", "43", "44",
	"45", "46", "47", "48",
	"49", "50", "51", "52",
	"53", "54", "55", "56",
	"57", "58", "59", 
};

static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo)
{
  GUI_RECT aRect;

  switch (pDrawItemInfo->Cmd) {
  case WIDGET_ITEM_DRAW_OVERLAY:
    /* 获取控件坐标 */
    aRect.x0 = pDrawItemInfo->x0;
    aRect.x1 = pDrawItemInfo->x1;
    aRect.y1 = pDrawItemInfo->y1;
    /* 画分割线 */
    GUI_SetColor(0x00E7E7E7);
    GUI_DrawLine(aRect.x0, (aRect.y1-19-16)/2, aRect.x1, (aRect.y1-19-16)/2);
    GUI_DrawLine(aRect.x0, (aRect.y1+19+16)/2, aRect.x1, (aRect.y1+19+16)/2);
    break;
  default:
    return LISTWHEEL_OwnerDraw(pDrawItemInfo);
  }
  return 0;
}

static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 26, 28, 800, 409, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 259, 270, 247, 90, 0, 0x0, 0 },
  { BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 553, 270, 199, 104, 0, 0x0, 0 },
  { LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_0, 140, 50, 60, 178, WM_CF_MEMDEV, 0x0, 0 },
  { LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_1, 234, 50, 100, 178, WM_CF_MEMDEV, 0x0, 0 },
  { LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_2, 300, 50, 50, 178, WM_CF_MEMDEV, 0x0, 0 },
	{ LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_3, 558, 50, 50, 178, WM_CF_MEMDEV, 0x0, 0 },
	{ LISTWHEEL_CreateIndirect, "", ID_LISTWHEEL_4, 630, 50, 50, 178, WM_CF_MEMDEV, 0x0, 0 },
	{ TEXT_CreateIndirect, "Text", ID_TEXT_0, 19, 116, 114, 53, 0, 0x64, 0 },
  { TEXT_CreateIndirect, "Text", ID_TEXT_1, 405, 116, 125, 58, 0, 0x64, 0 },
};
/*********************************************************************
*
*       Static code
*
**********************************************************************

/*********************************************************************
*
*       _cbDialog
*/	


static void _cbDialog(WM_MESSAGE * pMsg) {
  int NCode;
  int Id;
	WM_HWIN hItem;
	unsigned char index1;
  // USER START (Optionally insert additional variables)
  // USER END

	int i;
  switch (pMsg->MsgId) {
  /*****************************************************************************************
																					样式设置
	*****************************************************************************************/
	case WM_INIT_DIALOG:
		GUI_UC_SetEncodeUTF8();
		hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
    TEXT_SetFont(hItem, &GUI_Fonttime);
    TEXT_SetText(hItem, "日期:");
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
    TEXT_SetTextColor(hItem, 0x00000000);
    //
    // Initialization of 'Text'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
    TEXT_SetFont(hItem, &GUI_Fonttime);
    TEXT_SetText(hItem, "时间:");
    TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
	
		hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
    BUTTON_SetFont(hItem, &GUI_Fonttime);
    BUTTON_SetText(hItem, "修改系统时间");
		
		hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
    BUTTON_SetFont(hItem, &GUI_Fontshuju_anniu40);
    BUTTON_SetText(hItem, "返回");
			/* 初始化LISTWHEEL */
      for(i=0; i < 5; i++)
      {
        hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0 + i);
        LISTWHEEL_SetLineHeight(hItem, 34);
        LISTWHEEL_SetSnapPosition(hItem, (178-34)/2);
        LISTWHEEL_SetFont(hItem, GUI_FONT_20B_ASCII);
        LISTWHEEL_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
        LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_UNSEL, 0x191919);
        LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
        LISTWHEEL_SetDeceleration(hItem, 35);
        LISTWHEEL_SetOwnerDraw(hItem, _OwnerDraw);
        LISTWHEEL_SetSel(hItem, 0);
      }
	  /* 添加LISTWHEEL0文本项 */
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
      for(i=0;i<GUI_COUNTOF(_apYear);i++)
      {
        LISTWHEEL_AddString(hItem, *(_apYear+i));
      }
      /* 添加LISTWHEEL1文本项 */
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
      for(i=0;i<GUI_COUNTOF(_apMonth);i++)
      {
        LISTWHEEL_AddString(hItem, *(_apMonth+i));
      }
      /* 添加LISTWHEEL2文本项 */
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
      for(i=0;i<GUI_COUNTOF(_apDay);i++)
      {
        LISTWHEEL_AddString(hItem, *(_apDay+i));
      }
			  /* 添加LISTWHEEL3文本项 */
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_3);
      for(i=0;i<GUI_COUNTOF(_apHour);i++)
      {
        LISTWHEEL_AddString(hItem, *(_apHour+i));
      }
			  /* 添加LISTWHEEL4文本项 */
      hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_4);
      for(i=0;i<GUI_COUNTOF(_apMin);i++)
      {
        LISTWHEEL_AddString(hItem, *(_apMin+i));
      }
	break;
	/*****************************************************************************************
	*****************************************************************************************/
	case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_LISTWHEEL_0: // Notifications sent by 'Listwheel'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      case WM_NOTIFICATION_SEL_CHANGED:
           hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
            LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
            index1 = LISTWHEEL_GetPos(hItem);
            LISTWHEEL_SetSel(hItem,index1);
						LISTWHEEL_GetItemText(hItem,index1,Year,10);
        break;
      }
      break;
    case ID_BUTTON_0: //修改系统时间
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        break;
      case WM_NOTIFICATION_RELEASED:
				RTC_Set(atoi(Year),atoi(Month),atoi(Day),atoi(Hour),atoi(Min),00);
				printf("修改系统时间为%s-%s-%s %s:%s\r\n",Year,Month,Day,Hour,Min);
				GUI_MessageBox("Set Date & Time OK!","System MSG",0);
        break;
      }
      break;
    case ID_BUTTON_1: // Notifications sent by 'Button'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
        break;
      case WM_NOTIFICATION_RELEASED:
					GUI_EndDialog(confing_dialog,0);
					CreateFramewin();
        break;
      }
      break;
    case ID_LISTWHEEL_1: // Notifications sent by 'Listwheel'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      case WM_NOTIFICATION_SEL_CHANGED:
          hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_1);
            LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
            index1 = LISTWHEEL_GetPos(hItem);
            LISTWHEEL_SetSel(hItem,index1);
						LISTWHEEL_GetItemText(hItem,index1,Month,10);
        break;
      }
      break;
			case ID_LISTWHEEL_2: // Notifications sent by 'Listwheel'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      case WM_NOTIFICATION_SEL_CHANGED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_2);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
         index1 = LISTWHEEL_GetPos(hItem);
         LISTWHEEL_SetSel(hItem,index1);
				 LISTWHEEL_GetItemText(hItem,index1,Day,10);
        break;
      }
      break;
				case ID_LISTWHEEL_3: // Notifications sent by 'Listwheel'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_3);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      case WM_NOTIFICATION_SEL_CHANGED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_3);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
         index1 = LISTWHEEL_GetPos(hItem);
         LISTWHEEL_SetSel(hItem,index1);
				 LISTWHEEL_GetItemText(hItem,index1,Hour,10);
        break;
      }
      break;
				case ID_LISTWHEEL_4: // Notifications sent by 'Listwheel'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_4);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x191919);
        break;
      case WM_NOTIFICATION_RELEASED:
        break;
      case WM_NOTIFICATION_SEL_CHANGED:
         hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_4);
         LISTWHEEL_SetTextColor(hItem, LISTWHEEL_CI_SEL, 0x007dfe);
         index1 = LISTWHEEL_GetPos(hItem);
         LISTWHEEL_SetSel(hItem,index1);
				 LISTWHEEL_GetItemText(hItem,index1,Min,10);
        break;
      }
      break;
    }
	break;
  default:
    WM_DefaultProc(pMsg);
    break;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       CreateWindow
*/
WM_HWIN CreateTimeSetWindow(void);
WM_HWIN CreateTimeSetWindow(void) {
  WM_HWIN hWin;
  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}


/*************************** End of file ****************************/
